<%@ page contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" %>
<jsp:include page="/share/top.jsp"/>
<%
    String path = request.getContextPath();
    String strPraId = "";
    String strChlId = "";
    strPraId = (String) request.getParameter("menuPare");
    strChlId = (String) request.getParameter("menuChild");
%>

<style type="text/css">
    #bg {
        display: none;
        position: absolute;
        top: 0%;
        left: 0%;
        width: 100%;
        height: 100%;
        background-color: black;
        z-index: 1001;
        -moz-opacity: 0.7;
        opacity: .70;
        filter: alpha(opacity=70);
    }

    #show {
        display: none;
        position: absolute;
        top: 40%;
        left: 45%;
        width: 10%;
        height: 15%;
        padding: 8px;
        border: 1px solid #E8E9F7;
        background-color: black;
        z-index: 1002;
        overflow: auto;
        background: url(<%=path%>/pic/waiting.gif);
        filter: "progid:DXImageTransform.Microsoft.AlphaImageLoader(sizingMethod='scale')";
        -moz-background-size: 100% 100%;
        background-size: 100% 100%;
    }
</style>
<form id="mailForm" method="post">
    <input type="hidden" name="num" id="num" value=""/>
    <input type="hidden" name="objectList" id="objectList" value=""/>
    <input type="hidden" name="selectAll" id="selectAll" value="true"/>
    <input type="hidden" name="commStr" id="commStr" value="<c:out value='${commStr}'/>"/>
</form>
<form action="<%=path%>/AreaCtrl/query.x">
    <input type="hidden" name="menuPare" value="<%=strPraId %>"/>
    <input type="hidden" name="menuChild" value="<%=strChlId %>"/>
    <div id="rightcontent">
        <div class="inner">
            <div class="title">
                <div class="border">
    <span class="searchbox">小区名称
    <select name="strCommCode">
    	<option value="">请选择小区</option>
    	<c:forEach var="comm" items="${commlist}">
    		<option value='<c:out value="${comm.commCode }"/>' <c:if
                    test="${comm.commCode==strCommCode }"> selected="selected"</c:if>>
    			<c:out value="${comm.commName}"/>
    		</option>
        </c:forEach>
    </select>
    </span>
                    <span class="searchbox">栋数名称<input type="text" name="strAreaName" class="searchtxt"
                                                       value="<c:out value='${strAreaName }'/>"/></span>

                    <span class="btnspan btnspanl"><span class="pic pic8"></span>
    <input type="button" class="btn" value="查询" onclick="queryOnclick();"/></span>
                </div>
            </div>

            <div class="tablecontent">
                <table class="table" cellpadding="0" cellspacing="0">
                    <thead>
                    <tr>
                        <th class="t1" style="width:33px;"><input type="checkbox" onclick="selectAll(this)"/>全选</th>
                        <th class="t2">栋数名称</th>
                        <th class="t2">小区名称</th>
                        <th class="t3">操作</th>
                    </tr>
                    </thead>
                    <tbody>
                    <c:set value="0" var="sum"/>
                    <c:forEach var="TblAreaDimBo" items="${tblAreaDims.list}" varStatus="e">
                        <c:set value="${sum + e.index}" var="sum"/>
                        <tr>
                            <td class="t1">
                                <input type="checkbox" name="ckMsg"
                                       value="<c:out value="${TblAreaDimBo.commCode}" />,<c:out value="${TblAreaDimBo.areaCode}" />"/>
                            </td>
                            <td class="t2"><c:out value="${TblAreaDimBo.areaName}"/>栋</td>
                            <td class="t3"><c:out value="${TblAreaDimBo.commName}"/></td>
                            <td class="t4">
            <span class="btnoperal"><input type="button" value="修改" class="btn"
                                           onclick="document.location.href='<%=path%>/AreaCtrl/forSave.x?areaCode=<c:out
                                                   value="${TblAreaDimBo.areaCode }"/>&commCode=<c:out
                                                   value="${TblAreaDimBo.commCode }"/>&menuPare=<%=strPraId%>&menuChild=<%=strChlId%>';">
            </span>
                                <span class="btnoperal"><input type="button" value="删除" class="btn"
                                                               onclick="linkOnClick('0', '<c:out
                                                                       value="${TblAreaDimBo.areaCode }"/>', '<c:out
                                                                       value="${TblAreaDimBo.commCode }"/>');">
            </span>
                                <span class="btnoperal"><input type="button" value="单元生成" class="btn"
                                                               onclick="document.location.href='<%=path%>/BuildingCtrl/genBuildings.x?commCode=
                                                                   <c:out value="${TblAreaDimBo.commCode }"/>&areaCode=
                                                                   <c:out value="${TblAreaDimBo.areaCode }"/>&menuPare=<%=strPraId%>&menuChild=<%=strChlId%>';">
            </span></td>
                        </tr>
                    </c:forEach>
                    <c:if test="${sum > 0}">
                        <tr>
                            <td class="t4"><input type="checkbox" id="selectAllList" name="selectAllList"/>全选所有结果</td>
                            <td class="t1">请输入数字：</td>
                            <td class="t2">
                                <input type="text" name="roomAmount" id="roomAmount" class="searchtxt"
                                       style="width:100px;" value="1"/>
                                <span class="btnoperal"><input type="button" value="单元批量生成" class="btn"
                                                               onclick="createInfo();">
            </span>
                            </td>
                            <td class="t4">
            <span class="btnoperal"><input type="button" value="删除选中项" class="btn"
                                           onclick="deleteInfo();">
            </span>
                            </td>
                        </tr>
                    </c:if>
                    </tbody>
                </table>
            </div>
            <div class="page"><c:out value="${pr}" escapeXml="false"/></div>
        </div>
    </div>
    <div class="clear"></div>
    <div id="bg"></div>
    <div id="show"></div>
</form>
<jsp:include page="/share/foot.jsp"/>

<SCRIPT language="javascript">
    function createInfo() {
        var obj = $("#roomAmount").val();
        if (obj == null || obj == "") {
            alert("请输入单元数量");
            return false;
        }
        if (parseInt(obj) > 999) {
            alert("请输入1~999之间的数字");
            return false;
        }

        var cks = document.getElementsByName("ckMsg");
        var objectList = "";
        for (var i = 0; i < cks.length; i++) {
            if (cks[i].checked) {
                if (objectList.length != 0) {
                    objectList += "_";
                }
                objectList += cks[i].value;
            }
        }
        if (objectList.length == 0) {
            alert("请至少选择一条数据");
            return false;
        }
        else {
            $("#num").val(obj);
            $("#objectList").val(objectList);
            $("#mailForm").attr("action", "<%=path%>/BuildingCtrl/saveBatchs.x");
            $("#mailForm").submit();
            showdiv();
        }
    }
    function deleteInfo() {
        var selectAllList = document.getElementById("selectAllList");
        alert(selectAllList.checked);
        if (selectAllList.checked) {
            if (window.confirm('确定要删除选中的数据?')) {
                $("#selectAll").val("true");
                $("#mailForm").attr("action", "<%=path%>/AreaCtrl/remove.x");
                $("#mailForm").submit();
                showdiv();
            }
        } else {
            var cks = document.getElementsByName("ckMsg");
            var objectList = "";
            for (var i = 0; i < cks.length; i++) {
                if (cks[i].checked) {
                    if (objectList.length != 0) {
                        objectList += "_";
                    }
                    objectList += cks[i].value;
                }
            }
            if (objectList.length == 0) {
                alert("请至少选择一条数据");
                return false;
            }
            else if (window.confirm('确定要删除选中的数据?')) {
                $("#selectAll").val("false");
                $("#objectList").val(objectList);
                alert(objectList);
                $("#mailForm").attr("action", "<%=path%>/AreaCtrl/remove.x");
                $("#mailForm").submit();
                showdiv();
            }
        }
    }
    function linkOnClick(formName, areaCode, commCode) {
        if (window.confirm('确实要删除该栋数？')) {
            var form = document.forms[formName];
            form.action = "<%=path%>/AreaCtrl/remove.x&areaCode=" + areaCode + "&commCode=" + commCode;
            form.mehotd = "post";
            form.submit();
        }
    }
    function queryOnclick() {
        document.forms[0].submit();
    }
    function selectAll(me) {
        var cks = document.getElementsByName("ckMsg");
        var parms = "";
        var parmsLength = 0;
        for (var i = 0; i < cks.length; i++) {
            cks[i].checked = me.checked;
        }
    }
    function showdiv() {
        document.getElementById("bg").style.display = "block";
        document.getElementById("show").style.display = "block";
        $("#bg").css({"width": $(document).width(), "height": $(document).height()});
    }
</SCRIPT>